/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package logica.leitura;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 *
 * @author Thiago
 */
public class LeitorXLS {

    Workbook workbook;
    Sheet sheet;

    public LeitorXLS() {
        try {
            workbook = Workbook.getWorkbook(new File("dengue-95.xls"));
            sheet =  workbook.getSheet(0);
        } catch (IOException ex) {
            Logger.getLogger(LeitorXLS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (BiffException ex) {
            Logger.getLogger(LeitorXLS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public ArrayList<Integer> geraVertices(int semana) {

        ArrayList<Integer> listaDeVertices = new ArrayList<Integer>();

        if (semana <= 52) {
            for (int i = 5; i < 419; i++) {
                Cell celulaAtual = sheet.getCell((semana + 4), i-1);
                String conteudo = celulaAtual.getContents();
                Integer conteudoInteiro = Integer.parseInt(conteudo);
                if (conteudoInteiro > 0) {
                    Cell verticeAtual = sheet.getCell(0, i-1);
                    String verticeString = verticeAtual.getContents();
                    Integer verticeInteiro = Integer.parseInt(verticeString);
                    listaDeVertices.add(verticeInteiro);
                }
            }

            return listaDeVertices;
        } else {
            return null;
        }

    }



}
